|
1
|
|
|
// Require all dev dependencies. |
|
2
|
|
|
var gulp = require('gulp'), |
|
3
|
|
|
minify = require('gulp-minify'), |
|
4
|
|
|
watch = require('gulp-watch'), |
|
5
|
|
|
cleanCSS = require('gulp-clean-css'), |
|
6
|
|
|
rename = require('gulp-rename'), |
|
7
|
|
|
postcss = require('gulp-postcss'), |
|
8
|
|
|
bless = require('gulp-bless'), |
|
9
|
|
|
sass = require('gulp-sass'), |
|
10
|
|
|
zip = require('gulp-zip'), |
|
11
|
|
|
autoprefixer = require('autoprefixer'), |
|
12
|
|
|
browserSync = require('browser-sync').create(), |
|
13
|
|
|
imagemin = require('gulp-imagemin'); |
|
14
|
|
|
|
|
15
|
|
|
// me.js contains vars to your specific setup |
|
16
|
|
|
var me = require('../me.js'); |
|
17
|
|
|
|
|
18
|
|
|
var WEBSITE = me.WEBSITE, |
|
19
|
|
|
BASE_NAME = __dirname.match(/([^\/]*)\/*$/)[1]; |
|
20
|
|
|
|
|
21
|
|
|
// JS source, destination, and excludes. |
|
22
|
|
|
var JS_EXCLD = '!assets/js/*.min.js', |
|
23
|
|
|
JS_SRC = 'assets/js/*.js', |
|
24
|
|
|
JS_DEST = 'assets/js/'; |
|
25
|
|
|
|
|
26
|
|
|
// CSS and SASS src, dest, and exclude. |
|
27
|
|
|
var CSS_EXCLD = '!assets/css/*.min.css', |
|
28
|
|
|
CSS_SRC = 'assets/css/*.css', |
|
29
|
|
|
CSS_DEST = 'assets/css/', |
|
30
|
|
|
SASS_SRC = 'assets/scss/*.scss'; |
|
31
|
|
|
|
|
32
|
|
|
// Zip src and options. |
|
33
|
|
|
var ZIP_SRC_ARR = ['./**','!./composer.*', '!./gulpfile.js', '!./package.json', '!./README.md', '!./phpcs.xml', '!./phpunit.xml.dist', '!./{node_modules,node_modules/**}', '!./{bin,bin/**}', '!./{dist,dist/**}', '!./{vendor,vendor/**}', '!./{tests,tests/**}' ], |
|
34
|
|
|
ZIP_OPTS = { base: '..' }; |
|
35
|
|
|
|
|
36
|
|
|
// PHP Source. |
|
37
|
|
|
var PHP_SRC = '**/*.php'; |
|
38
|
|
|
|
|
39
|
|
|
/******************************************************************************* |
|
40
|
|
|
* Gulp Tasks |
|
41
|
|
|
******************************************************************************/ |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Default gulp task. Initializes browserSync proxy server and watches src files |
|
45
|
|
|
* for any changes. |
|
46
|
|
|
* |
|
47
|
|
|
* CMD: gulp |
|
48
|
|
|
*/ |
|
49
|
|
|
gulp.task('default', function() { |
|
50
|
|
|
|
|
51
|
|
|
browserSync.init({ |
|
52
|
|
|
proxy: WEBSITE |
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
gulp.watch( SASS_SRC, ['build-sass']); |
|
56
|
|
|
gulp.watch( CSS_SRC, ['build-css']); |
|
57
|
|
|
gulp.watch( JS_SRC , ['js-watch']); |
|
58
|
|
|
gulp.watch( PHP_SRC, function(){ |
|
59
|
|
|
browserSync.reload(); |
|
60
|
|
|
}); |
|
61
|
|
|
}); |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* JS Watch task. This is a dependency task for the default gulp task that |
|
65
|
|
|
* builds the js files and reloads the browser in the correct order |
|
66
|
|
|
* |
|
67
|
|
|
* CMD: None. Not meant to be run as standalone command. |
|
68
|
|
|
*/ |
|
69
|
|
|
gulp.task('js-watch', ['build-js'], function(){ |
|
70
|
|
|
browserSync.reload(); |
|
71
|
|
|
}); |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Build CSS task. This task adds vendor specific prefixes to CSS rules, minifies |
|
75
|
|
|
* the files and injects the changes to the browser. |
|
76
|
|
|
* |
|
77
|
|
|
* CMD: gulp build-css |
|
78
|
|
|
*/ |
|
79
|
|
|
gulp.task('build-css', function() { |
|
80
|
|
|
gulp.src( [ CSS_SRC, CSS_EXCLD ] ) |
|
81
|
|
|
.pipe(postcss([ |
|
82
|
|
|
autoprefixer({browsers: ['> 5% in US']}) |
|
83
|
|
|
])) |
|
84
|
|
|
//.pipe(bless()) |
|
85
|
|
|
.pipe(cleanCSS({compatibility: 'ie8'})) |
|
86
|
|
|
.pipe(rename({suffix: '.min'})) |
|
87
|
|
|
.pipe(gulp.dest( CSS_DEST )) |
|
88
|
|
|
.pipe(browserSync.stream()); |
|
89
|
|
|
}); |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Compiles SCSS into regular CSS. |
|
93
|
|
|
* |
|
94
|
|
|
* CMD: gulp build-sass |
|
95
|
|
|
*/ |
|
96
|
|
|
gulp.task('build-sass', function() { |
|
97
|
|
|
gulp.src( SASS_SRC ) |
|
98
|
|
|
.pipe(sass().on('error', sass.logError)) |
|
99
|
|
|
.pipe(gulp.dest(CSS_DEST)); |
|
100
|
|
|
}); |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Minifies JS files. |
|
104
|
|
|
* |
|
105
|
|
|
* CMD: gulp build-js |
|
106
|
|
|
*/ |
|
107
|
|
|
gulp.task('build-js', function(){ |
|
108
|
|
|
gulp.src( [ JS_SRC, JS_EXCLD ] ) |
|
109
|
|
|
.pipe(minify({ |
|
110
|
|
|
ext:{ |
|
111
|
|
|
src:'.js', |
|
112
|
|
|
min:'.min.js' |
|
113
|
|
|
}, |
|
114
|
|
|
noSource: true |
|
115
|
|
|
})) |
|
116
|
|
|
.pipe(gulp.dest( JS_DEST )); |
|
117
|
|
|
}); |
|
118
|
|
|
|
|
119
|
|
|
gulp.task('build-img', function(){ |
|
120
|
|
|
gulp.src('assets/images/*') |
|
121
|
|
|
.pipe(imagemin()) |
|
122
|
|
|
.pipe(gulp.dest('assets/images')); |
|
123
|
|
|
}); |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Executes all of the build tasks in the correct sequence. |
|
127
|
|
|
* |
|
128
|
|
|
* CMD: gulp build |
|
129
|
|
|
*/ |
|
130
|
|
|
gulp.task('build', ['build-sass','build-css','build-js', 'build-img']); |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Creates a zip file of the current project without any of the config and dev |
|
134
|
|
|
* files and saves it under the 'dist' folder. |
|
135
|
|
|
* |
|
136
|
|
|
* CMD: gulp zip |
|
137
|
|
|
*/ |
|
138
|
|
|
gulp.task('zip', function(){ |
|
139
|
|
|
return gulp.src( ZIP_SRC_ARR, ZIP_OPTS ) |
|
140
|
|
|
.pipe( zip( BASE_NAME + '.zip' ) ) |
|
141
|
|
|
.pipe( gulp.dest('dist') ); |
|
142
|
|
|
}); |
|
143
|
|
|
|